{extends 'base/site2.html'}
{block name="page_header"}{include file="common/header.html" inline}{/block}
{block name="page_nav"}{include file="common/slide-nav.html" inline}{/block}
{block name="page_styles"}
<link rel="stylesheet" type="text/css" href="/css/mediation/entryrepay/index.css" />
{/block}

{block name="page_section"}


<div class="sessionPage bg-fff">
    <input type="hidden" id="delete_id" value="">
    <div class="page-header">
        <div class="left">
            <span class="line"></span>
            <strong class="tit">还款计划</strong>
        </div>
    </div>
    <form class="small-style" method="get"  id="form-ele"  action="" class="clearfix" role="validform" enctype="multipart/form-data">
        <div class="form_row">
            <input type="hidden" name="limit" value="{if $query.limit}{$query.limit}{/if}">
            <div class="form-group  col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">调解部门:</label>
                <div class="col-sm-7">
                    <select class="form-control" name="mediationOrganId">
                        <option class="u144_input_option"  {if $query.mediationOrganId=='0'}selected="selected"{/if} value="0">全部</option>
                        {foreach from=$mediationOrgan item=item key=key}
                        <option class="u144_input_option" {if $query.mediationOrganId==$key}selected="selected"{/if} value="{$key}">{$item.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">调解员:</label>
                <div class="col-sm-7">
                    <select class="form-control" id="is_contrast" name="mediatorId">
                        <option class="u144_input_option" {if $query.mediatorId==0}selected="selected"{/if} value="0">全部</option>
                        {foreach from=$mediator item=item }
                        {if $item.id != 1}
                        <option class="u144_input_option" {if $query.mediatorId == $item.id}selected="selected"{/if} value="{$item.id}">{$item.name}</option>
                        {/if}
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">资产方:</label>
                <div class="col-sm-7">
                    <select class="form-control selectpicker"   title="请选择" name="assetsId" id="assetsId">
                        {foreach from=$assets  item=info}
                        <option class="u144_input_option" {if !empty($query.assetsId) &&  $info.id == $query.assetsId}selected="selected"{/if} value="{$info.id}">{$info.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">还款状态:</label>
                <div class="col-sm-7">
                    <select class="form-control selectpicker" name="status" id="newzttype" title="请选择">
                        {foreach from=$repayStatusArr key=key item=item}
                        <option class="u144_input_option" {if $query.status=={$key}}selected="selected"{/if} value="{$key}">{$item}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

        </div>
        <div class="form_row">
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">当事人:</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control noempty col-sm-4"  value="{if !empty($query.litigantName)}{$query.litigantName}{/if}" name="litigantName" id="litigantName" placeholder="请输入~">
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">案件号:</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control noempty col-sm-4"  value="{if !empty($query.caseId)}{$query.caseId}{/if}" name="caseId" id="caseId" placeholder="请输入~">
                </div>
            </div>

            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">还款日:</label>
                <div class="col-sm-7">
                    <select class="form-control selectpicker"   title="请选择" name="repaymentDate" id="repaymentDate">
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  1 == $query.repaymentDate}selected="selected"{/if} value="1">每月1日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  2 == $query.repaymentDate}selected="selected"{/if}  value="2">每月2日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  3 == $query.repaymentDate}selected="selected"{/if}  value="3">每月3日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  4 == $query.repaymentDate}selected="selected"{/if}  value="4">每月4日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  5 == $query.repaymentDate}selected="selected"{/if}  value="5">每月5日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  6 == $query.repaymentDate}selected="selected"{/if}  value="6">每月6日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  7 == $query.repaymentDate}selected="selected"{/if}  value="7">每月7日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  8 == $query.repaymentDate}selected="selected"{/if}  value="8">每月8日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  9 == $query.repaymentDate}selected="selected"{/if}  value="9">每月9日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  10 == $query.repaymentDate}selected="selected"{/if}  value="10">每月10日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  11 == $query.repaymentDate}selected="selected"{/if}  value="11">每月11日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  12 == $query.repaymentDate}selected="selected"{/if}  value="12">每月12日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  13 == $query.repaymentDate}selected="selected"{/if}  value="13">每月13日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  14 == $query.repaymentDate}selected="selected"{/if}  value="14">每月14日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  15 == $query.repaymentDate}selected="selected"{/if}  value="15">每月15日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  16 == $query.repaymentDate}selected="selected"{/if}  value="16">每月16日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  17 == $query.repaymentDate}selected="selected"{/if}  value="17">每月17日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  18 == $query.repaymentDate}selected="selected"{/if}  value="18">每月18日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  19 == $query.repaymentDate}selected="selected"{/if}  value="19">每月19日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  20 == $query.repaymentDate}selected="selected"{/if}  value="20">每月20日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  21 == $query.repaymentDate}selected="selected"{/if}  value="21">每月21日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  22 == $query.repaymentDate}selected="selected"{/if}  value="22">每月22日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  23 == $query.repaymentDate}selected="selected"{/if}  value="23">每月23日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  24 == $query.repaymentDate}selected="selected"{/if}  value="24">每月24日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  25 == $query.repaymentDate}selected="selected"{/if}  value="25">每月25日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  26 == $query.repaymentDate}selected="selected"{/if}  value="26">每月26日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  27 == $query.repaymentDate}selected="selected"{/if}  value="27">每月27日</option>
                        <option class="u144_input_option" {if !empty($query.repaymentDate) &&  28 == $query.repaymentDate}selected="selected"{/if}  value="28">每月28日</option>
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">案件标识号:</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control noempty col-sm-4"  value="{if !empty($query.batshId)}{$query.batshId}{/if}" name="batshId" id="batshId" placeholder="请输入~">
                </div>
            </div>
        </div>
        <div class="form_row">
            <div class="form-group col-lg-3 ui-select">
                <label for="exampleInputName2"  class="col-sm-4 control-label">上传批次号:</label>
                <div class="col-sm-7">
                    <input type="text" class="form-control noempty col-sm-4"  value="{if !empty($query.importRecordId)}{$query.importRecordId}{/if}" name="importRecordId" id="importRecordId" placeholder="请输入~">
                </div>
            </div>
            <div class="form-group col-lg-3 ui-select">
                <div class="col-lg-5">
                    <button class="btn btn-primary col-lg-8 shousuoBtn"><span class="nav-icon glyphicon glyphicon-search" aria-hidden="true" style="margin-right: 2px"></span>查询</button>
                </div>
                <div class="col-lg-5">
                    <a type="button" href="/returnedmoneyplan/index" class="btn btn-default col-lg-8" ><span class="nav-icon glyphicon glyphicon-refresh" aria-hidden="true" style="margin-right: 2px"></span>重置</a>
                </div>
                <div class="col-lg-5" style="float: right;">
                    <button  class="btn btn-info col-lg-8 data_upload"><span class="nav-icon glyphicon glyphicon-download-alt" aria-hidden="true" style="margin-right: 2px"></span>导出</button>
                </div>
            </div>
            <div class="ui-select"></div>
            <div class="ui-select"></div>
        </div>
    </form >
    <div style="width: 95%;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        overflow-x: scroll;">
        <span >计划还款总额 {number_format($totalrepayAmount,2)} 元 , 已还总额 {number_format($totalrepaidAmount,2)} 元 , 本月计划还款 {number_format($this_repayAmount,2)} 元 当前实际还款 {number_format($this_realRepayAmount,2)} 元 , 下月预计还款 {number_format($next_realRepayAmount,2)} 元</span>
        <table class="table table-striped table-bordered table-hover text-nowrap">
            <thead>
            <tr>
                <th><input type="checkbox" class="checkall" style="vertical-align: text-bottom"></th>
                <th scope="col">调解组</th>
                <th scope="col">案件号</th>
                <th scope="col">当事人</th>
                <th scope="col">负责人</th>
                <th scope="col">还款状态</th>
                <th scope="col">还款日</th>
                <th scope="col">计划金额</th>
                <th scope="col">已还金额</th>
                <th scope="col">本月应还</th>
                <th scope="col">本月还款</th>
                <th scope="col">下月应还</th>
                <th scope="col">还款期数</th>
                <th scope="col">已还期数</th>
                <th scope="col">添加时间</th>
                <th scope="col" class="fix-ele">操作</th>
            </tr>
            </thead>
            <tbody>
            {if $list}
            {foreach from=$list item=info key=key name=a}
            <tr>
                <td> <input name="checkItem" class="j-check" type="checkbox" value="{$info.id}"></td>
                <td>{$mediationOrgan[$info['mediationOrganId']]['name']}</td>
                <td>{$info['caseId']}</td>
                <td>{$info['litigantName']}</td>
                <td>{$info['mediatorName']}</td>
                <td>{$repayStatusArr[$info['status']]}</td>
                <td>每月{$info['repaymentDate']}日</td>
                <td>{$info['repayAmount']}</td>
                <td>{$info['repaidAmount']}</td>
                <td>
                    {if empty($detail[$info['id']]['this']['repayAmount'])}
                    0.00
                    {else}
                    {$detail[$info['id']]['this']['repayAmount']}
                    {/if}
                </td>
                <td>
                    {if !empty($detail[$info['id']]['this']['isRepay']) && $detail[$info['id']]['this']['isRepay'] == 1}
                    已还
                    {else}
                    未还
                    {/if}
                </td>
                <td>
                    {if empty($detail[$info['id']]['next']['repayAmount'])}
                    0.00
                    {else}
                    {$detail[$info['id']]['next']['repayAmount']}
                    {/if}
                </td>
                <td>{$info['numberOfPayments']}</td>
                <td>{$info['numberOfRepaid']}</td>
                <td>{$info['addTime']|date_format:"%Y/%m/%d %H:%M:%S"}</td>
                <td class="fix-ele">
                    <a href="/returnedmoneyplan/detail?id={$info['id']}&litigantName={$info['litigantName']}" >详情</a>
                    {if $info['status'] == 'wait_repay' || $admin['role_id'] == 1}
                    <a  onclick="confirm('请确认是否删除该条数据？') ? clickDel(this,{$info.id}) : '' " >删除</a>
                    {/if}
                </td>
            </tr>
            {/foreach}
            {/if}
            </tbody>
        </table>
    </div>
    <div class="mr-b20 col-lg-12 pad-no" style="float:none;">
        <input type="button" value="转移计划" id='transfer' data-toggle="modal" data-target="#modal_transfer" data-id='' class="btn btn-primary">
    </div>
    <div class="clearfix pad-no text-nowrap" style="margin-top: 20px;">
        {include file="base/pagenav.html"  action="/returnedmoneyplan/index" pagenum=$curPageNum inline}
        <select class="form-control" id="paglimit" style="float:right;margin:0 10px;width: auto;margin-top: -5px;">
            <option value="limit=10" {if $query.limit==10}selected="selected"{/if}>10条/页</option>
            <option value="limit=20" {if $query.limit==20}selected="selected"{/if}>20条/页</option>
            <option value="limit=50" {if $query.limit==50}selected="selected"{/if}>50条/页</option>
            <option value="limit=100" {if $query.limit==100}selected="selected"{/if}>100条/页</option>
        </select>
        <span style="float:right;">共 {$totalnum} 条</span>
    </div>
</div>

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">提醒</h4>
            </div>
            <div class="modal-body">
                <div class="modal-con">
                    <p>确定删除该条数据么？</p>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary deletesure">确定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="modal_transfer" tabindex="-1" role="dialog" aria-labelledby="refusal_modal" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">转移计划</h4>
            </div>
            <div class="modal-body">
                <form id="transfer_form">
                    <div class="form_dialog form-group col-lg-10 ui-select">
                        <label for="exampleInputName2"  class="col-sm-4 control-label">调解员:</label>
                        <div class="col-sm-9">
                            <select class="form-control" id="mediators_id" name="mediators_id">
                                <option value="" >——请选择——</option>
                                {foreach from=$mediator item=info}
                                <option class="u144_input_option" value="{$info.id}">{$info.name}</option>
                                {/foreach}
                            </select>
                        </div>

                        <input type="hidden" value="" id="transfer_plan_ids" name="transfer_plan_ids">

                    </div>
                    </br>
                    </br>

                </form>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button type="button" class="btn btn-default" id="fpclosebtn" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary distribution_transfer">确定</button>
            </div>


        </div>
    </div>
</div>

{/block}
{block name="page_scripts"}
<script type="text/javascript">
    lockfas = false;

    $(".data_upload").on("click",function(){
        var is_down =confirm('请确认是否下载？\n'+ '下载时间可能比较慢,点击后请耐心等待!') ;
        if(is_down){
            $("#form-ele").attr('action','/returnedmoneyplan/planexport');
            $("#form-ele").submit();

        }
    });
    $(".shousuoBtn").on("click",function(){
        $("#form-ele").attr('action','');
        $("#form-ele").submit();

    });
    $("#transfer").on("click",function(){
        var arrbtn = [];
        $(".j-check:checked").each(function (index, ele) {
            //遍历所有复选框，然后取值进行 !非操作
            if ($(this).prop("checked")) {
                arrbtn.push($(this).val());
            }
        })
        if(arrbtn.length==0){
            toastr.error('请选择案件');
            return false;
        }
        var ids=arrbtn.toString();
        $("#transfer_plan_ids").val(ids);
        console.log(arrbtn);
        $("#modal_transfer").show();
    });

    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    $('body').on('change','#paglimit', function(){
        console.log()
        var mediationOrganId = GetQueryString('mediationOrganId');
        var paglimit = GetQueryString('limit');
        var val =  $(this).val();
        if(!mediationOrganId){
            if(!paglimit){
                window.location = window.location.href+'?'+val;
            } else{
                window.location = window.location.href.replace('limit='+paglimit,val);
            }
        }else{
            if(!paglimit){
                window.location = window.location.href+'&'+val;
            } else{
                window.location = window.location.href.replace('limit='+paglimit,val);
            }
        }
    })
        .on('click', '.checkall', function(){
            //全选
            $(".j-check,.checkall").prop("checked", $(this).prop("checked"));

        })
        //反选
        .on('change','j-check', function(){
            if ($(".j-check:checked").length == $(".j-check").length) {
                $(".checkall").prop("checked", true);
            } else {
                $(".checkall").prop("checked", false);
            }
        })
        .on('click', '.distribution_transfer', function(){
            if(lockfas)return;
            lockfas = true;
            arrcaseid = [];
            if($("#transfer_case_ids").val()==0){
                toastr.error('请选择案件');
                return false;
            }
            $.ajax({
                url:"/returnedmoneyplan/transferPlan",
                method:"post",
                data:$("#transfer_form").serialize(),
                success:function(res){
                    if(res.code==200){
                        lockfas = false;
                        toastr.success("转移计划成功");
                        setTimeout(function(){
                            window.location.reload();
                        },2000)
                    }else{
                        lockfas = false;
                        toastr.error(res.message);

                    }
                }
            })
            lockfas = false;

        })


    function clickDel($this,id){
        var _this= $(this) ;
        if($(this).attr('disabled')){
            return false;
        }
        $(this).attr('disabled',true);
        $.ajax({
            url:"/returnedmoneyplan/delplan",
            method:"post",
            data:{
                plan_id:id
            },
            success:function(res){
                if(res.code==200){
                    toastr.success(res.message);
                    document.location.reload();
                }else{
                    toastr.error(res.message);
                }
                _this.attr('disabled',false);
            }
        })

    }

</script>
{/block}
